#-*- coding: utf-8 -*-
'''
Created on Aug 27, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table
from sqlalchemy.orm import mapper
    
class ConfigDish(object):

    _Mapper_ = None
    _company_id_ = -1
    _shop_id_ = -1    
    def __init__(self):
        self.id = 0
        self.search_name = ''
        self.dish_name = ''
        self.dish_class_id = 0
        self.is_print_item = 0
        self.is_mark = 0
        self.is_set_dinner = 0
        self.class_statistics = 0
        self.rank_id = 0
        self.printer_name = ''
        self.digit_search_id = 0
        
    @staticmethod
    def doMapping(company_id, shop_id):
        '''
        按company_id分库，shop_id对应公司分店，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if ConfigDish._company_id_ == company_id and ConfigDish._shop_id_ == shop_id:
            return
                
        if ConfigDish._Mapper_ is not None:
            ConfigDish._Mapper_.dispose()
            
        metaData = MetaData()
        configDishTable = Table('config_dish', metaData,
                           Column('id', Integer, primary_key = True),
                           Column('search_name', String),
                           Column('dish_name', String),
                           Column('dish_class_id', Integer),
                           Column('is_print_item', Integer),
                           Column('is_mark', Integer),
                           Column('is_set_dinner', Integer),
                           Column('class_statistics', Integer),
                           Column('rank_id', Integer),
                           Column('printer_name', String),
                           Column('digit_search_id', Integer),
                           schema = "shop_%s_%s" % (company_id, shop_id))
        
        ConfigDish._Mapper_ = mapper(ConfigDish, configDishTable)
    